#ifndef THREADPOOL_H_
#define THREADPOOL_H_

#include <pthread.h>
#include <unistd.h>
#include <sys/select.h>
#include <sys/socket.h>
#include "queue.h"

typedef enum
{
    FREE,
    RUNNING,
    JOINABLE,
    CLOSED
} state;

typedef struct
{
    int thread_fds_[MAXFDPERTHREAD];
    int numfd_;
    int thread_pipe_[2];
    pthread_t thread_identifer_;
    state thread_state_;

    pthread_mutex_t *pool_mu_; 
    pthread_cond_t *pool_cond_;
    ArrayQueue *pool_queue_;

} ClerkThread_t;

typedef struct
{
    pthread_t thread_indentider_;

    pthread_mutex_t *pool_mu_;
    pthread_cond_t *pool_cond_;
    ArrayQueue *pool_queue_;

} WorkerThread_t;

typedef struct 
{
    ClerkThread_t clerk_threads[MAXTHREAD];
    WorkerThread_t workers_[MAXWORKER];
    ArrayQueue queue_;
    pthread_mutex_t mu_;
    pthread_cond_t cond_;

} ThreadPool;

void init_thread_pool(ThreadPool *pool);

void close_thread_pool(ThreadPool *pool);

int add_fd(ThreadPool *pool, int fd);


void *run_clerk(void *);
void *run_worker(void *);

#endif